palPalEntry(255) As PALETTEENTRY ' Enough for 256 colors
End Type
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Private Type PicBmp
Size As Long
Type As Long
hBmp As Long
hPal As Long
Reserved As Long
End Type
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal iCapabilitiy As Long) As Long
Private Declare Function GetSystemPaletteEntries Lib "gdi32" (ByVal hdc As Long, ByVal wStartIndex As Long, ByVal wNumEntries As Long, lpPaletteEntries As PALETTEENTRY) As Long
Private Declare Function CreatePalette Lib "gdi32" (lpLogPalette As LOGPALETTE) As Long
Private Declare Function SelectPalette Lib "gdi32" (ByVal hdc As Long, ByVal hPalette As Long, ByVal bForceBackground As Long) As Long
Private Declare Function RealizePalette Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function WindowFromDC Lib "user32" (ByVal hdc As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function CreatePatternBrush Lib "gdi32" (ByVal hBitmap As Long) As Long
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hdc As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Private Declare Function CreateDIBSection Lib "gdi32" (ByVal hdc As Long, pBitmapInfo As BITMAPINFO, ByVal un As Long, ByVal lplpVoid As Long, ByVal Handle As Long, ByVal dw As Long) As Long
Private Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Public Sub Create(ByVal bpp As Long, ByVal Width As Long, ByVal Height As Long, Optional ByVal Planes As Long = 1)
Dispose
With bi.bmiHeader
.biBitCount = bpp
.biHeight = Height
.biWidth = Width
.biPlanes = Planes
.biSize = Len(bi.bmiHeader)
.biCompression = 0
End With
dcHandle = CreateCompatibleDC(0)
hDIB = CreateDIBSection(dcHandle, bi, 0, 0, 0, 0)
SelectObject dcHandle, hDIB
End Sub
Friend Property Get Handle()
Handle = dcHandle
End Property
Public Sub Dispose()
DeleteObject hDIB
DeleteDC dcHandle
ReleaseDC WindowFromDC(dcHandle), dcHandle
End Sub
Public Sub Clear(ByVal bgColor As Long)
Dim hPen As Long, hBrush As Long, OldPen As Long, OldBrush As Long
hPen = CreatePen(PS_NULL, 0, 0)
hBrush = CreateSolidBrush(bgColor)
OldPen = SelectObject(dcHandle, hPen)
OldBrush = SelectObject(dcHandle, hBrush)
Rectangle dcHandle, 0, 0, Width, Height
SelectObject dcHandle, OldPen
SelectObject dcHandle, OldBrush
DeleteObject hPen
DeleteObject hBrush
End Sub
Public Sub GetBitmap(ByVal hBitmap As Long, ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long)
Dim hPen As Long, hBrush As Long, OldPen As Long, OldBrush As Long
hPen = CreatePen(PS_NULL, 0, 0)
hBrush = CreatePatternBrush(hBitmap)
OldPen = SelectObject(dcHandle, hPen)
OldBrush = SelectObject(dcHandle, hBrush)
Rectangle dcHandle, X, Y, Width, Height
SelectObject dcHandle, OldPen
SelectObject dcHandle, OldBrush
DeleteObject hPen
DeleteObject hBrush
End Sub
Public Function ConvertToBitmap(ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long) As StdPicture
Set ConvertToBitmap = hDCToPicture(dcHandle, X, Y, Width, Height)
End Function
Public Sub SetToDC(ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long, ByVal SrcX As Long, ByVal SrcY As Long, ByVal SrcWidth As Long, ByVal SrcHeight As Long, ByVal Quality As Long, ByVal OperationCode As Long)